package jjn.jdk;

import java.util.Calendar;

class SwitchDemo {
    public static void main(String[] args) {
        Calendar today = Calendar.getInstance();
        int month = today.get(Calendar.MONTH);
        int year = today.get(Calendar.YEAR);
        
        int daysInMonth;
        switch (month) {
            case Calendar.JANUARY, Calendar.MARCH, Calendar.MAY, Calendar.JULY, Calendar.AUGUST,
                    Calendar.OCTOBER, Calendar.DECEMBER -> daysInMonth = 31;
            case Calendar.APRIL, Calendar.JUNE, Calendar.SEPTEMBER, Calendar.NOVEMBER -> daysInMonth = 30;
            case Calendar.FEBRUARY -> {
                if (((year % 4 == 0) && !(year % 100 == 0))
                        || (year % 400 == 0)) {
                    daysInMonth = 29;
                } else {
                    daysInMonth = 28;
                }
            }
            default -> throw new IllegalArgumentException("Unknown case for JDK");
        }
        
        System.out.println(
                "There are " + daysInMonth + " days in this month.");
    }
}